package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.User;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/mapper/UserMapper.class */
public interface UserMapper {
    @Select({"<script>" +
            "select u.id,u.name,u.username,u.tel,u.unit_id,u.role_id,r.role_name," +
            "c.company_name,d.department_name,u.department_id,u.uuid from user u " +
            "left join role r on r.id = u.role_id " +
            "left join company c on c.id = u.unit_id " +
            "left join department d on d.id = u.department_id " +
            "<where>" +
            "<if test='name != null and name.length &gt; 0'> u.name like concat('%',#{name},'%')</if>" +
            "<if test='departmentId != null'> u.department_id = #{departmentId}</if>" +
            "</where>" +
            "</script>"})
    @Results(id = "map", value = {@Result(property = "unitId", column = "unit_id"),
            @Result(property = "roleId", column = "role_id"),
            @Result(property = "roleName", column = "role_name"),
            @Result(property = "companyName", column = "company_name"),
            @Result(property = "departmentName", column = "department_name"),
            @Result(property = "departmentId", column = "department_id")})
    List<User> findAllUser(@Param("name") String str, @Param("departmentId") Integer num);

    @Insert({"insert into user (name,username,password,tel,unit_id,role_id,department_id,signature_password,create_time) values (#{name},#{username},#{password},#{tel},#{unitId},#{roleId},#{departmentId},#{signaturePassword},#{createTime})"})
    Integer addUser(User user);

    @Update({"<script>" +
            "update user " +
            "<set>" +
            "<if test='name != null and name.length &gt; 0'>name=#{name},</if>" +
            "<if test='password != null and password.length &gt; 0'>password=#{password},</if>" +
            "<if test='tel != null and tel.length &gt; 0'>tel=#{tel},</if>" +
            "<if test='unitId != null '>unit_id=#{unitId}," +
            "</if><if test='roleId != null '>role_id=#{roleId},</if>" +
            "<if test='departmentId != null '>department_id=#{departmentId},</if>" +
            "<if test='username != null and username.length &gt;= 0'>username=#{username},</if>" +
            "<if test='updateTime != null and updateTime.length &gt;= 0'>update_time=#{updateTime}</if>" +
            "</set>" +
            "where id=#{id}" +
            "</script>"})
    Integer updateUser(User user);

    @Delete({"delete from user where id=#{id}"})
    Integer deleteUser(int i);

    @Select({"select u.*,r.role_name,r.permissions,r.find_all,c.company_name,c.id as company_id, " +
            "r.project_view,u.first_time_login,u.first_time_signature,d.department_name " +
            "from user u left join role r on r.id = u.role_id left join company c on c.id = u.unit_id " +
            "left join department d on d.id = u.department_id where u.username = #{username} "})
    @Results({@Result(property = "unitId", column = "unit_id"), @Result(property = "roleId", column = "role_id"),
            @Result(property = "roleName", column = "role_name"), @Result(property = "findAll", column = "find_all"),
            @Result(property = "companyName", column = "company_name"), @Result(property = "companyId", column = "company_id"),
            @Result(property = "projectView", column = "project_view"), @Result(property = "firstTimeLogin", column = "first_time_login"),
            @Result(property = "firstTimeSignature", column = "first_time_signature"), @Result(property = "departmentName", column = "department_name"), @Result(property = "departmentId", column = "department_id"), @Result(property = "signaturePassword", column = "signature_password")})
    User findByUsername(String str);

    @Select({"select u.*,r.role_name,r.permissions,r.find_all,c.company_name,c.id as company_id, r.project_view,u.first_time_login,u.first_time_signature,d.department_name from user u left join role r on r.id = u.role_id left join company c on c.id = u.unit_id left join department d on d.id = u.department_id where u.id = #{id} "})
    @Results({@Result(property = "unitId", column = "unit_id"), @Result(property = "roleId", column = "role_id"), @Result(property = "roleName", column = "role_name"), @Result(property = "findAll", column = "find_all"), @Result(property = "companyName", column = "company_name"), @Result(property = "companyId", column = "company_id"), @Result(property = "projectView", column = "project_view"), @Result(property = "firstTimeLogin", column = "first_time_login"), @Result(property = "firstTimeSignature", column = "first_time_signature"), @Result(property = "departmentName", column = "department_name"), @Result(property = "departmentId", column = "department_id"), @Result(property = "signaturePassword", column = "signature_password")})
    User findByUserId(Integer num);

    @Update({"<script>" +
            "update user <set>" +
            "<if test='password != null and password.length &gt; 0'>password=#{password},</if>" +
            "<if test='firstTimeLogin != null '>first_time_login=#{firstTimeLogin},</if>" +
            "<if test='signatureLastTime != null '>signature_last_time=#{signatureLastTime},</if>" +
            "<if test='signaturePassword != null '>signature_password=#{signaturePassword},</if>" +
            "</set>where id=#{id}</script>"})
    Integer updateByUserNP(Integer id, String password, Integer firstTimeLogin, String signatureLastTime, String signaturePassword);

    @Update({"<script>update user <set><if test='signaturePassword != null and signaturePassword.length &gt; 0'>signature_password=#{signaturePassword},</if><if test='firstTimeSignature != null '>first_time_signature=#{firstTimeSignature},</if></set>where id=#{id}</script>"})
    Integer updateByUserNPSignature(Integer num, String str, Integer num2);

    @Select({"select password from user where id = #{id}"})
    String findById(Integer num);

    @Select({"select signature_last_time from user where id = #{id}"})
    String selectSignatureTime(Integer num);

    @ResultMap({"map"})
    @Select({"<script>" +
            "select u.id,u.name,u.username,u.tel,u.unit_id,u.role_id,r.role_name,c.company_name,d.department_name " +
            "from user u left join role r on r.id = u.role_id left join company c on c.id = u.unit_id " +
            "left join department d on d.id = u.department_id <where> u.id =#{id} " +
            "</where>  " +
            "</script>"})
    User findUserById(@Param("id") Integer id);

    @Select({"<script>select name from user <where>  id in <foreach collection='ids' item='item' index='index' open='(' separator=',' close=')'> #{item} </foreach></where>  </script>"})
    List<String> findByIds(@Param("ids") String[] strArr);

    @Select({"select uuid from user where username = #{username}"})
    String selectUuid(String username);

    @Update({"update user set uuid = #{uuid} where username=#{username}"})
    Integer updateUuidByUserName(@Param("uuid") String uuid, @Param("username") String username);

    @Update({"update user set uuid = null where id=#{id}"})
    Integer updateUuidById( @Param("id") Integer id);
}